﻿@model ADZ_APPUpGradeInfo
@{
    ViewBag.Title = "版本管理";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    var viewModel = Model ?? new ADZ_APPUpGradeInfo();
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
}

<form class="definewidth m20" action="@Url.Action("EditEdition", "Edition")" method="post" enctype="multipart/form-data">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="15%" class="tableleft">系统版本号<em>*</em></td>
            <td>
                <input type="text" class="abc input-default" value="@viewModel.SystemVersion" name="SystemVersion"  />
                <input type="hidden" value="@viewModel.ID" />
            </td>
        </tr>
        <tr>
            <td width="15%" class="tableleft">程序包下载地址<em>*</em></td>
            <td>
                <div id="modify_div">
                    <input type="text" class="abc input-default" value="@viewModel.DowloadAddress" name="DowloadAddress" style="width:500px;" />
                    <input type="button" id="reupload_btn" onclick="$('#upload_div').show(); $('#modify_div').hide();" class="btn btn-primary" value="重新上传文件" />
                </div>
                <div id="upload_div" style="display:none;">
                    <input type="file" name="File" id="File" /> @*accept="application/vnd.android.package-archive">*@
                    <input type="button" id="reupload_btn_ext" onclick="$('#upload_div').hide(); $('#modify_div').show(); $('#File').val('');" class="btn btn-primary" value="取消上传" />
                </div>
            </td>
        </tr>
        <tr>
            <td width="15%" class="tableleft">是否强制更新<em>*</em></td>
            <td>
                <select id="IsForced" name="IsForced">
                    <option value="" @(viewModel.IsForced == -1 ? "selected" : "")>请选择</option>
                    <option value="0" @(viewModel.IsForced == 0 ? "selected" : "")>否</option>
                    <option value="1" @(viewModel.IsForced == 1 ? "selected" : "")>是</option>
                </select>
            </td>
        </tr>
        <tr>
            <td width="15%" class="tableleft">系统类型<em>*</em></td>
            <td>
                <select id="SystemType" name="SystemType" style="width:150px;" onchange="ShowFile()">
                    <option value="" @(viewModel.SystemType == 0 ? "selected" : "")>请选择</option>
                    <option value="1" @(viewModel.SystemType == 1 ? "selected" : "")>andriod版</option>
                    <option value="2" @(viewModel.SystemType == 2 ? "selected" : "")>IOS版</option>
                </select>
                <script>
                    function ShowFile() {
                        var system_type = $("#SystemType").val();
                        $('#upload_div').hide();
                        $('#modify_div').show();
                        $('#File').val('');
                        if (system_type === "1") {
                            $('#reupload_btn').show();
                        }
                        if (system_type === "2") {
                            $('#reupload_btn').hide();
                        }
                    }
                    ShowFile();
                </script>
            </td>
        </tr>
        <tr>
            <td width="15%" class="tableleft">内部版本号</td>
            <td><input type="text" class="abc input-default"  value="@viewModel.InnoVersion" name="InnoVersion" /></td>
        </tr>
        <tr>
            <td width="15%" class="tableleft">最近的强制升级内部版本号</td>
            <td><input type="text" class="abc input-default" value="@viewModel.LastForceInnoVersion" name="LastForceInnoVersion" /></td>
        </tr>
        <tr>
            <td width="15%" class="tableleft">升级内容描述</td>
            <td>
                <textarea class="abc input-default" name="Description" style="width:600px; height:250px;">@viewModel.Description</textarea>
            </td>
        </tr>
        <tr>
            <td width="15%" class="tableleft"></td>
            <td>
                <p><span id="spMsg"></span></p>
                <input type="Submit" id="Submit" class="btn btn-primary" value="确认" /> &nbsp;&nbsp;&nbsp;
                <input type="button" id="btnreturn" class="btn btn-success" value="返回版本号列表" />
            </td>
        </tr>
       
    </table>
    <script>
        BUI.use('bui/overlay', function (overlay) {
            function showSucc(obj, url) {
                BUI.Message.Alert(obj, function () {
                    location.href = url;
                }, 'success');
            }
            $(function () {
                

                $('#btnreturn').on('click', function () {
                    window.document.location.href = "@Url.Action("EditionList", "Edition")";
                });


                jQuery.validator.addMethod("Version", function (value, element) {
                    var cardno = /^[0-9]*$/;
                    return this.optional(element) || (cardno.test(value));
                }, "只能输入数字0-9");


                var validator = $('form').validate({
                    errorLabelContainer: $("#errorContainer"),
                    errorElement: "span",
                    rules: {
                        IsForced: { required: true },
                        SystemType: { required: true },
                        DowloadAddress: { required: true, rangelength: [1, 1000] },
                        SystemVersion: { required: true },
                        IsNotified: { required: true },
                        Description: { rangelength: [1, 2500] },
                        InnoVersion: { Version: true },
                        LastForceInnoVersion: { Version: true }

                    },
                    messages: {
                        IsForced: { required: "请选择是否强制更新" },
                        SystemType: { required: "请选择系统类型" },
                        DowloadAddress: { required: "请输入程序包下载地址", rangelength: "只能输入1-1000个字符" },
                        SystemVersion: { required: "请输入系统版本号" },
                        IsNotified: { required: "是否推送过系统更新消息" },
                        Description: { rangelength: "只能输入1-2500个字符" },
                        InnoVersion: { Version: "只能输入数字0-9" },
                        LastForceInnoVersion: { Version: "只能输入数字0-9" }
                    },
                    submitHandler: function (form) {

                        $(form).ajaxSubmit(function (result) {
                            ShowActionResult(result, function () {
                                document.location = "@Url.Action("EditionList","Edition")";
                            });
                        });

                        BUI.Message.Alert("正在上传，请稍候！", function () {
                        }, 'success');
                    }
                });
            });
        });

    </script>
</form>